package logic

import (
	"context"
	"torchsr/utils"

	"torchsr/internal/svc"
	"torchsr/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddTaskCancelLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewAddTaskCancelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddTaskCancelLogic {
	return &AddTaskCancelLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *AddTaskCancelLogic) AddTaskCancel(req *types.AddTaskCancelReq) (resp *types.AddTaskCancelResp, err error) {
	// todo: add your logic here and delete this line

	status, _ := utils.GetTaskGuidFromRedis(req.TaskId)
	if status == utils.QUEUED {
		utils.SetTaskGuidToRedis(req.TaskId, utils.CANCEL)
		resp = &types.AddTaskCancelResp{IsCanceled: true}
	} else {
		resp = &types.AddTaskCancelResp{IsCanceled: false}
	}

	return resp, nil
}
